var querystring = require('querystring')
var http = require('http')

const postData = querystring.stringify({
    'question[title]': null,
    'question[content]': '<p>kanbule</p>',
    'question[courseId]': 461,
    'question[lessonId]': 11751,
    '_csrf_token': 'ad056e7fe577c4229e9b6c1a373c129bf4728b73',
  });
  
  const options = {
    hostname: 'www.codingke.com',
    port: 80,
    path: '/ajax/create/course/question',
    method: 'POST',
    headers: {
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Encoding': 'gzip, deflate',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Connection': 'keep-alive',
        'Content-Length': postData.length,
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Cookie': 'tgw_l7_route=ba4a4fa767ccc5ac6060ead23a114820; PHPSESSID=87obv1jah4abbgcq9pfe7nvir3; UM_distinctid=17227c83aeecf-009cd760815d61-d373666-144000-17227c83af03d7; CNZZDATA1256018185=1888258065-1589802302-%7C1589802302; Hm_lvt_7d5fe787f1dd300413ad4b53656dc0b1=1589805333; Invite_code=338807; 53gid2=10240442533013; visitor_type=new; 53gid0=10240442533013; 53gid1=10240442533013; 53revisit=1589805334375; 53kf_72165667_from_host=www.codingke.com; 53kf_72165667_land_page=http%253A%252F%252Fwww.codingke.com%252F; kf_72165667_land_page_ok=1; 53uvid=1; onliner_zdfq72165667=0; 53kf_72165667_keyword=http%3A%2F%2Fwww.codingke.com%2F; Hm_lpvt_7d5fe787f1dd300413ad4b53656dc0b1=1589805363',
        'Host': 'www.codingke.com',
        'Origin': 'http://www.codingke.com',
        'Referer': 'http://www.codingke.com/v/11751-lesson-461-course',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
        'X-CSRF-Token': 'ad056e7fe577c4229e9b6c1a373c129bf4728b73',
        'X-Requested-With': 'XMLHttpRequest'
    }
  };
  
  const req = http.request(options, (res) => {
    console.log(`状态码: ${res.statusCode}`);
    console.log(`响应头: ${JSON.stringify(res.headers)}`);
    res.setEncoding('utf8');
    res.on('data', (chunk) => {
      console.log(`响应主体: ${chunk}`);
    });
    res.on('end', () => {
      console.log('响应中已无数据');
    });
  });
  
  req.on('error', (e) => {
    console.error(`请求遇到问题: ${e.message}`);
  });
  
  // 将数据写入请求主体。
  req.write(postData);
  req.end();